package com.bac.bacplatform;

import java.util.HashMap;
import java.util.Map;

import com.android.volley.Response;
import com.android.volley.Response.Listener;
import com.bac.utils.Config;
import com.bac.utils.Util;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class ResetLoginPwdActivity extends BaseActivity implements OnClickListener{

	private EditText mEt_code,mEt_newPwd;
	private Button mBtn_reset;
	private String code_str,newPwd_str;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.reset_login_pwd);
	}

	@Override
	public void init() {
		mEt_code = (EditText) findViewById(R.id.et_username);
		mEt_newPwd = (EditText) findViewById(R.id.phone_hint);
		mBtn_reset = (Button) findViewById(R.id.loginpassword_ok_btn);
		mBtn_reset.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.loginpassword_ok_btn:
			//重置登录密码
			resetLoginPwd();
			break;

		default:
			break;
		}
		
	}

	private void resetLoginPwd() {
		/**
		 * 成功返回结果
		 */
		Listener<String> sL = new Response.Listener<String>() {
			@Override
			public void onResponse(String response) {
				dismissLoadingProgress();
				Log.i("TAG----success", response.toString());
				showToast("重置成功，请重新登录");
				Intent intentToLogin = new Intent(ResetLoginPwdActivity.this,LoginActivity.class);
				startActivity(intentToLogin);
			}
		};
		
		code_str = mEt_code.getText().toString();
		newPwd_str = mEt_newPwd.getText().toString();
		
		if (code_str.length() <= 0) {
			showToast(R.string.phone_none);
			return;
		} else if (newPwd_str.length() <= 0) {
			showToast(R.string.password_none);
			return;
		}
		showLoadingProgress();
		String path = Config.URL_RESET_PWD_BY_CODE;
		Map<String, String> map = new HashMap<String, String>();
		String id_str = this.getIntent().getStringExtra("id");
		map.put("id", id_str);
		map.put("code", code_str);
		map.put("password", newPwd_str);
		Util.httpStringPost(path, sL, this, map);
	}

}
